<template>
  <transition name="slide-fade">
    <div
      v-if="id && visible"
      class="x-container"
      :style="{ 'z-index': zIndex }"
    >
      <el-button
        class="close-btn"
        type="primary"
        icon="el-icon-close"
        @click="close"
      />
      <el-card id="slide" ref="slide" class="box-card">
        <div slot="header" class="clearfix">
          <div class="head-top">
            <img :src="require('@/assets/img/duty.png')" alt="" />
            <span>{{ detailData.dutyname }}</span>
          </div>
          <div class="head-bottom u-flex">
            <div class="row">任务类型：{{ detailData.dutytypename }}</div>
            <div class="row">
              任务状态：
              <el-tag :type="detailData.dutystatus | statusFilter">{{
                detailData.dutystatus | formatStatus
              }}</el-tag>
            </div>
            <div class="row">执行人：{{ detailData.executename }}</div>
          </div>
        </div>

        <div class="d-container-bd">
          <el-tabs type="border-card" v-model="tabCurrentName">
            <el-tab-pane
              v-for="(item, index) in tabNames"
              :key="index"
              :label="item.label"
              :name="item.name"
              lazy
            >
              <component
                :is="item.name"
                :detail="detailData"
                :id="id"
                tablename="duty"
              />
            </el-tab-pane>
          </el-tabs>
        </div>
      </el-card>
    </div>
  </transition>
</template>

<script>
import { getMaxIndex } from "@/utils/index";
import { getDutyById } from "@/api/common";
import DetailMixins from "@/views/mixins/Detail";
export default {
  name: "WatchDetail",

  mixins: [DetailMixins],

  data() {
    return {
      zIndex: getMaxIndex(),
    };
  },

  props: {
    /** 任务ID */
    id: [String, Number],

    visible: {
      type: Boolean,
      default: false,
    },
  },

  mounted() {},

  watch: {
    id: {
      handler(newVal, oldVal) {
        if (newVal) {
          this.getDutyById(newVal);
        }
      },
      deep: true,
      immediate: true,
    },
  },

  methods: {
    close() {
      this.$emit("close");
    },
    /**获取详情 */
    getDutyById(id) {
      getDutyById({ dutyid: id }).then((res) => {
        this.detailData = res.Data[0];
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.slide-fade-enter-active,
.slide-fade-leave-active {
  will-change: transform;
  transition: all 0.35s ease;
}
.slide-fade-enter,
.slide-fade-leave-to {
  transform: translateX(100%);
}
.x-container {
  position: fixed;
  min-width: 600px;
  width: 65%;
  height: calc(100vh - 50px);
  top: 50px;
  bottom: 0px;
  right: 0px;
}
.close-btn {
  position: absolute;
  top: 160px;
  left: -40px;
  z-index: 1;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  padding: 6px;

  ::v-deep {
    i {
      font-size: 26px;
    }
  }
}
.box-card {
  width: 100%;
  height: 100%;
  font-size: 13px;
  background: #f5f6f9;

  .clearfix {
    background: #fff;
    .head-top {
      position: relative;
      margin-bottom: 10px;
      font-size: 16px;
      font-weight: 600;
      img {
        width: 35px;
        height: 35px;
        margin-right: 10px;
      }
      span {
        position: absolute;
        bottom: 5px;
      }
    }

    .head-bottom {
      .row {
        margin-right: 30px;
        min-width: 150px;
      }
    }
  }
}
</style>